package com.example.hospitalsystem.controller;

import com.example.hospitalsystem.pojo.dto.department.AddDepartmentDto;
import com.example.hospitalsystem.pojo.dto.department.DepartmentPageQueryDto;
import com.example.hospitalsystem.pojo.entity.Department;
import com.example.hospitalsystem.pojo.entity.Pharmacy;
import com.example.hospitalsystem.result.Result;
import com.example.hospitalsystem.service.DepartmentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/department")
@Tag(name="7.科室模块")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    @Operation(summary = "管理员获取所有科室信息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/getAllDepartmentInfo")
    public Result<Object> getAllDepartmentInfo(@RequestBody DepartmentPageQueryDto departmentPageQueryDto){
        return departmentService.getAllDepartmentInfo(departmentPageQueryDto);
    }

    @Operation(summary = "添加科室信息", security = {@SecurityRequirement(name = "Authorization")})
    @PostMapping("/addDepartmentInfo")
    public Result<Object> addDepartment(@RequestBody AddDepartmentDto addDepartmentDto){
        return departmentService.addDepartnment(addDepartmentDto);
    }

    @Operation(summary = "删除科室信息", security = {@SecurityRequirement(name = "Authorization")})
    @DeleteMapping("/deleteDepartment/{id}")
    public Result<Object> deleteDepartment(@PathVariable("id") int id){
        return departmentService.deleteDepartment(id);
    }

    @Operation(summary = "返回科室列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/departmentList")
    public Result<Object> departmentList(){
        List<Department> list = departmentService.getDepartmentList();
        return Result.ok(list);
    }

    @Operation(summary = "根据id查询科室信息", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/departmentInfo/{id}")
    public Result<Object> getDepartmentInfoById(@PathVariable("id") Integer departmentId){
        return departmentService.getDepartmentInfoById(departmentId);
    }

    @Operation(summary = "搜索科室", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/search")
    public Result<Object> searchDepartment(String key){
        List<Department> list = departmentService.searchDepartment(key);
        return Result.ok(list);
    }

}
